
from flask import Flask, render_template, jsonify, request
from handles.getdatas import *
import settings
from flask_cors import CORS

app = Flask(__name__)
app.config.from_object(settings)
CORS(app)

@app.route('/')
def hello_world():  # put application's code here
    return render_template('datas.html')


# task1
@app.route('/task1/marketName=<mk_name>', methods=['POST', 'GET'])
def task1(mk_name):
    selected_market = request.form.get('market_name')
    if selected_market:
        market_data = h_task1(selected_market)
        return jsonify(market_data)
    else:
        market_data = h_task1(mk_name)
        return jsonify(market_data)

# task1b
@app.route('/task1b/marketName=<mk_name>', methods=['POST', 'GET'])
def task1b(mk_name):
    selected_market = request.form.get('market_name')
    if selected_market:
        market_data = h_task1b(selected_market)
        return jsonify(market_data)
    else:
        market_data = h_task1b(mk_name)
        return jsonify(market_data)

# task2
@app.route('/task2/marketName=<mk_name>', methods=['POST', 'GET'])
def task2(mk_name):
    selected_market = request.form.get('market_name')
    if selected_market:
        market_data = h_task2(selected_market)
        return jsonify(market_data)
    else:
        market_data = h_task2(mk_name)
        return jsonify(market_data)


# task3
@app.route('/task3/marketName=<mk_name>', methods=['POST', 'GET'])
def task3(mk_name):
    selected_market = request.form.get('market_name')
    if selected_market:
        market_data = h_task3(selected_market)
        return jsonify(market_data)
    else:
        market_data = h_task3(mk_name)
        return jsonify(market_data)


# -------------------------------------------------------------------------------
@app.route('/task3b/marketName=<mk_name>', methods=['POST', 'GET'])
def task3b(mk_name):
    selected_market = request.form.get('market_name')
    if selected_market:
        market_data = h_task3b(selected_market)
        return jsonify(market_data)
    else:
        market_data = h_task3b(mk_name)
        return jsonify(market_data)


# task4
@app.route('/task4/marketName=<mk_name>', methods=['POST', 'GET'])
def task4(mk_name):
    selected_market = request.form.get('market_name')
    if selected_market:
        market_data = h_task4(selected_market)
        return jsonify(market_data)
    else:
        market_data = h_task4(mk_name)
        return jsonify(market_data)


# task5
@app.route('/task5/marketName=<mk_name>', methods=['POST', 'GET'])
def task5(mk_name):
    selected_market = request.form.get('market_name')
    if selected_market:
        market_data = h_task5(selected_market)
        return jsonify(market_data)
    else:
        market_data = h_task5(mk_name)
        return jsonify(market_data)


@app.route('/task6/marketName=<mk_name>', methods=['POST', 'GET'])
def task6(mk_name):
    selected_market = request.form.get('market_name')
    if selected_market:
        market_data = h_task6(selected_market)
        return jsonify(market_data)
    else:
        market_data = h_task6(mk_name)
        return jsonify(market_data)


@app.route('/task7/marketName=<mk_name>', methods=['POST', 'GET'])
def task7(mk_name):
    selected_market = request.form.get('market_name')
    if selected_market:
        market_data = h_task7(selected_market)
        return jsonify(market_data)
    else:
        market_data = h_task7(mk_name)
        return jsonify(market_data)


@app.route('/task8/marketName=<mk_name>', methods=['POST', 'GET'])
def task8(mk_name):
    selected_market = request.form.get('market_name')
    if selected_market:
        market_data = h_task8(selected_market)
        return jsonify(market_data)
    else:
        market_data = h_task8(mk_name)
        return jsonify(market_data)
# -----------------------------------------------------------------------------
@app.route('/get_market_names', methods=['GET'])
def market_name():
    mk_name = get_market_name()
    return jsonify(mk_name)


if __name__ == '__main__':
    app.run(debug=True)
